<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blogs/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blogs/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/blogs/images/favicon.ico">
  <link rel="mask-icon" href="/blogs/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blogs/css/main.css">


<link rel="stylesheet" href="/blogs/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://tretea.gitee.io').hostname,
    root: '/blogs/',
    scheme: 'Gemini',
    version: '7.6.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="计算机网络基础知识">
<meta property="og:type" content="article">
<meta property="og:title" content="计算机网络基础">
<meta property="og:url" content="https://tretea.gitee.io/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="小叶子的个人博客">
<meta property="og:description" content="计算机网络基础知识">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E4%B8%83%E5%B1%82%E5%8D%8F%E8%AE%AE.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E7%89%A9%E7%90%86%E5%B1%82.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E5%B9%BF%E6%92%AD.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E7%BD%91%E7%BB%9C%E5%B1%82.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/tcp%E6%8A%A5%E6%96%87.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/tcp%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E5%BA%94%E7%94%A8%E5%B1%82.jpg">
<meta property="og:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/dns%E5%8D%8F%E8%AE%AE.jpg">
<meta property="article:published_time" content="2020-02-12T06:03:41.000Z">
<meta property="article:modified_time" content="2020-03-28T11:01:57.307Z">
<meta property="article:author" content="小叶子">
<meta property="article:tag" content="计算机网络基础">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://tretea.gitee.io/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E4%B8%83%E5%B1%82%E5%8D%8F%E8%AE%AE.jpg">

<link rel="canonical" href="https://tretea.gitee.io/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>计算机网络基础 | 小叶子的个人博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/blogs/atom.xml" title="小叶子的个人博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>
    <a href="https://github.com/tretea" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blogs/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">小叶子的个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blogs/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blogs/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blogs/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blogs/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blogs/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="none"
           placeholder="搜索..." spellcheck="false"
           type="text" id="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://tretea.gitee.io/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blogs/images/%E5%B0%8F%E5%8F%B6%E5%AD%90.jpg">
      <meta itemprop="name" content="小叶子">
      <meta itemprop="description" content="也许我会走的很慢，但我不会停下来">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="小叶子的个人博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          计算机网络基础
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-02-12 14:03:41" itemprop="dateCreated datePublished" datetime="2020-02-12T14:03:41+08:00">2020-02-12</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-03-28 19:01:57" itemprop="dateModified" datetime="2020-03-28T19:01:57+08:00">2020-03-28</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blogs/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index">
                    <span itemprop="name">计算机基础</span>
                  </a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/#comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>6 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>计算机网络基础知识</p>
<a id="more"></a>
<h1 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h1><p>文本参考 <a href="https://www.cnblogs.com/linhaifeng/articles/5937962.html#_label1" target="_blank" rel="noopener">https://www.cnblogs.com/linhaifeng/articles/5937962.html#_label1</a><br>本文图片均来源于 <a href="https://www.cnblogs.com/linhaifeng/articles/5937962.html#_label1" target="_blank" rel="noopener">https://www.cnblogs.com/linhaifeng/articles/5937962.html#_label1</a> </p>
<h1 id="一、什么叫计算机网络"><a href="#一、什么叫计算机网络" class="headerlink" title="一、什么叫计算机网络"></a>一、什么叫计算机网络</h1><p>计算机网络 : 由计算机组成的资源共享的通道交织在一起形成的网络,通过这个网络,计算机可以访问任意一台计算机,也可以被任意一台计算机访问</p>
<h1 id="二、基础概念"><a href="#二、基础概念" class="headerlink" title="二、基础概念"></a>二、基础概念</h1><h3 id="1-协议"><a href="#1-协议" class="headerlink" title="1.协议"></a>1.协议</h3><p>协议 : 规范,是生产计算机硬件以及制作计算机软件的厂家共同商定的一套网络传输规范  </p>
<h3 id="2-以太网"><a href="#2-以太网" class="headerlink" title="2.以太网"></a>2.以太网</h3><p>以太网 :<br>以太网出现原因ip地址不够用,在同个局域网内,ip使用自己小范围内规定的ip,访问外网,在使用IP地址<br>(1)局域网,若干台相离较近的计算机,以电磁波为传输介质,进行数据交换</p>
<p>(2)城域网,以网线作为传播媒介,进行数据交换</p>
<h3 id="3-数据帧"><a href="#3-数据帧" class="headerlink" title="3.数据帧"></a>3.数据帧</h3><p>数据帧就是一个单位的数据,一个单位的数据只能有固定字节,超出部分会另外封装</p>
<h3 id="4-子网"><a href="#4-子网" class="headerlink" title="4.子网"></a>4.子网</h3><p>广域网-&gt;城域网-&gt;局域网<br>广域网 : 就是Internet,最大的网,能访问世界上任意地方的网络<br>城域网 : 就是一座城市的网络,属于Internet的子网<br>局域网 : 范围更小,属于Internet的子网</p>
<h1 id="三、计算机通信过程"><a href="#三、计算机通信过程" class="headerlink" title="三、计算机通信过程"></a>三、计算机通信过程</h1><h3 id="1-osi七层协议、tcp-ip五层协议、tcp-ip四层协议"><a href="#1-osi七层协议、tcp-ip五层协议、tcp-ip四层协议" class="headerlink" title="1.osi七层协议、tcp/ip五层协议、tcp/ip四层协议"></a>1.osi七层协议、tcp/ip五层协议、tcp/ip四层协议</h3><p>tcp/ip五层协议可以准确描述计算机之间信息的传递过程<br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E4%B8%83%E5%B1%82%E5%8D%8F%E8%AE%AE.jpg" alt></p>
<h3 id="2-物理层"><a href="#2-物理层" class="headerlink" title="2.物理层"></a>2.物理层</h3><p>(1)网卡 (2)路由器 (3)光纤 (4)电缆 (5)无线电 等等<br>物理层工作原理 : 信息在计算机之间以电信号的形式发送、传递、接受<br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E7%89%A9%E7%90%86%E5%B1%82.jpg" alt></p>
<h3 id="3-数据链路层"><a href="#3-数据链路层" class="headerlink" title="3.数据链路层"></a>3.数据链路层</h3><p>数据链路层由来：单纯的电信号0和1没有任何意义，必须规定电信号多少位一组，每组什么意思<br>数据链路层的功能：定义了电信号的分组方式</p>
<h5 id="3-1-以太网协议"><a href="#3-1-以太网协议" class="headerlink" title="3.1 以太网协议"></a>3.1 以太网协议</h5><p>以太网协议规定了局域网内计算机信息传递时的形式 :</p>
<table>
<thead>
<tr>
<th align="center">head</th>
<th align="center">data</th>
</tr>
</thead>
</table>
<p>head : (1)发送地址 6字节 (2)接受地址 6字节 (3)数据类型 6字节<br>data : 传递的数据 46字节~1500字节<br><font style="color:red">如果发送的数据在规定字节之内,就一次性发送,否则就分批次发送</font></p>
<h5 id="3-2-mac地址"><a href="#3-2-mac地址" class="headerlink" title="3.2 mac地址"></a>3.2 mac地址</h5><p>mac地址 : 每台电脑在出场之后会在网卡上刻上一个全世界独一无二的标识,这个标识就是这台电脑上的mac地址<br>以太网协议上的地址就是mac地址</p>
<h5 id="3-3-广播"><a href="#3-3-广播" class="headerlink" title="3.3 广播"></a>3.3 广播</h5><p>局域网内的数据传播就是以广播的形式<br>发送地址 : 发送机的mac地址<br>接受地址 : 接受机的mac地址<br>数据形式 : 以太网协议<br>传播介质 : 电磁波<br>一个房间内有A,B,C,D四台主机电脑,主机A要向主机B发送 ‘Hello World’<br>&lt;1&gt;将数据包装成数据帧,以下形式</p>
<table>
<thead>
<tr>
<th align="center">目标MAC地址</th>
<th align="center">发送者MAC地址</th>
<th align="center">数据类型</th>
<th align="center">数据</th>
</tr>
</thead>
</table>
<p>&lt;2&gt;以广播的形式利用电磁波发送数据<br>&lt;3&gt;计算机BCD都接收到了数据<br>&lt;4&gt;计算机BCD开始拆分数据,当看到目标MAC地址时,判断是否是自己,不是自己就丢弃数据,是自己就继续拆分,接收数据<br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E5%B9%BF%E6%92%AD.jpg" alt></p>
<h3 id="4-网络层"><a href="#4-网络层" class="headerlink" title="4.网络层"></a>4.网络层</h3><p>世界范围的互联网是由一个个彼此隔离的小的局域网组成的,局域网的交互有空间限制,只能由数台看得到的计算机交互,如果是国内的计算机想访问国外的服务器就无法用以广播的形式访问,网络层就由此而生  </p>
<p>Internet是由无数个局域网组成,消息传递只能先从局域网之间传递,在传递到本机,但mac地址无法区分一台电脑属于哪个子网,所以引入了IP地址</p>
<h5 id="1-IP协议"><a href="#1-IP协议" class="headerlink" title="1.IP协议"></a>1.IP协议</h5><p>IP地址:0.0.0.0 ~ 255.255.255(十进制)<br>00000000.00000000.00000000.00000000 ~ 11111111.11111111.11111111.11111111(二进制)<br>IP地址分为两部分 : 1.子网标识  2.主机标识<br>IP地址是有限的,用户太多,IP不够用,所以IPv6出现  </p>
<h5 id="2-子网掩码-用于分辨两个ip是否处于同一个局域网内"><a href="#2-子网掩码-用于分辨两个ip是否处于同一个局域网内" class="headerlink" title="2.子网掩码 : 用于分辨两个ip是否处于同一个局域网内"></a>2.子网掩码 : 用于分辨两个ip是否处于同一个局域网内</h5><p>将ip转换为二进制,与二进制的子网掩码进行与运算,得到网络标识<br>将ip转换为二进制,与二进制的子网掩码进行取反运算,得到主机标识<br>子网掩码格式 :</p>
<table>
<thead>
<tr>
<th align="center">类别</th>
<th align="center">子网掩码的二进制数值</th>
<th align="center">子网掩码的十进制数值</th>
</tr>
</thead>
<tbody><tr>
<td align="center">A</td>
<td align="center">11111111 . 00000000 . 00000000 . 00000000</td>
<td align="center">255.0.0.0</td>
</tr>
<tr>
<td align="center">B</td>
<td align="center">11111111 . 11111111 . 00000000 . 00000000</td>
<td align="center">255.255.0.0</td>
</tr>
<tr>
<td align="center">C</td>
<td align="center">11111111 . 11111111 . 11111111 . 00000000</td>
<td align="center">255.255.255.0</td>
</tr>
</tbody></table>
<h5 id="3-IP数据包"><a href="#3-IP数据包" class="headerlink" title="3.IP数据包"></a>3.IP数据包</h5><table>
<thead>
<tr>
<th align="center">以太网头</th>
<th align="center">ip 头</th>
<th align="center">数据</th>
</tr>
</thead>
</table>
<p>head：长度为20到60字节<br>data：最长为65,515字节。<br>而以太网数据包的”数据”部分，最长只有1500字节。因此，如果IP数据包超过了1500字节，它就需要分割成几个以太网数据包，分开发送了。                   </p>
<h5 id="ARP协议"><a href="#ARP协议" class="headerlink" title="ARP协议"></a>ARP协议</h5><p>以太网协议规定 : 源地址和目标地址是mac地址,但是存在一个问题,自己电脑的mac地址是已知的,但目标mac地址不知道,ARP协议就是通过ip获取目标mac地址  </p>
<p>网关 : 两个局域网联系的’门神’  </p>
<p>假设两个教室是两个相互独立的局域网,A教室的同学A想联系B教室的同学B,A同学先将信息告诉网关A,网关A在告诉网关B,网关B在告诉同学B  </p>
<p>数据格式 :  </p>
<table>
<thead>
<tr>
<th align="center"></th>
<th align="center">源mac</th>
<th align="center">目标mac</th>
<th align="center">源ip</th>
<th align="center">目标ip</th>
<th align="center">数据部分</th>
</tr>
</thead>
<tbody><tr>
<td align="center">发送端主机</td>
<td align="center">发送端mac</td>
<td align="center">FF:FF:FF:FF:FF:FF</td>
<td align="center">172.16.10.10/24</td>
<td align="center">172.16.10.11/24</td>
<td align="center">数据</td>
</tr>
</tbody></table>
<p>数据传递过程 :<br>情景1 : 在同一个局域网内,源主机以广播的方式发送以上数据格式的数据,局域网内的每一个主机都接收到了信息,开始拆分信息,发现目标mac为FF:FF:FF:FF:FF:FF,继续拆分,发现目标ip,不是自己就丢弃,是自己就向源mac地址发送自己的mac地址,源主机就获取到了目标主机的mac地址  </p>
<p>情景2 : 不在同一个局域网内,源主机以广播的方式发送以上数据格式的数据,局域网内的每一个主机都接收到了信息,开始拆分信息,发现目标mac为FF:FF:FF:FF:FF:FF,继续拆分,发现目标ip,不是自己就丢弃,网关发现目标ip为自己的ip,就把自己的mac地址发送给源主机<br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E7%BD%91%E7%BB%9C%E5%B1%82.jpg" alt></p>
<h3 id="5-传输层"><a href="#5-传输层" class="headerlink" title="5.传输层"></a>5.传输层</h3><p>ip地址用来找到子网,mac地址用来确定主机,而一台主机上有多个应用,微信,qq,浏览器,那么数据到底是传给那个应用呢,不同应用之间就是通过端口号来区分的  </p>
<p>传输层就是建立端口到端口之间的连接</p>
<p>补充：端口范围0-65535，0-1023为系统占用端口</p>
<h5 id="1-TCP协议"><a href="#1-TCP协议" class="headerlink" title="1.TCP协议"></a>1.TCP协议</h5><p>TCP协议是端口到端口的数据传输协议,可靠传输，TCP数据包没有长度限制，理论上可以无限长，但是为了保证网络的效率，通常TCP数据包的长度不会超过IP数据包的长度<br>数据格式 :  </p>
<table>
<thead>
<tr>
<th align="center">以太网头</th>
<th align="center">ip 头</th>
<th align="center">tcp头</th>
<th align="center">数据</th>
</tr>
</thead>
</table>
<p><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/tcp%E6%8A%A5%E6%96%87.jpg" alt><br><strong>tcp三次握手和四次挥手</strong><br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/tcp%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B.jpg" alt></p>
<h5 id="2-UDP协议"><a href="#2-UDP协议" class="headerlink" title="2.UDP协议"></a>2.UDP协议</h5><p>不可靠传输，”报头”部分一共只有8个字节，总长度不超过65,535字节，正好放进一个IP数据包。</p>
<table>
<thead>
<tr>
<th align="center">以太网头</th>
<th align="center">ip 头</th>
<th align="center">udp头</th>
<th align="center">数据</th>
</tr>
</thead>
</table>
<h3 id="6-应用层"><a href="#6-应用层" class="headerlink" title="6.应用层"></a>6.应用层</h3><p>应用层由来：用户使用的都是应用程序，均工作于应用层，互联网是开发的，大家都可以开发自己的应用程序，数据多种多样，必须规定好数据的组织形式 </p>
<p>应用层功能：规定应用程序的数据格式。</p>
<p>例：TCP协议可以为各种各样的程序传递数据，比如Email、WWW、FTP等等。那么，必须有不同协议规定电子邮件、网页、FTP数据的格式，这些应用程序协议就构成了”应用层”。<br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/%E5%BA%94%E7%94%A8%E5%B1%82.jpg" alt></p>
<h3 id="7-网络通信模拟"><a href="#7-网络通信模拟" class="headerlink" title="7.网络通信模拟"></a>7.网络通信模拟</h3><h5 id="假设一个工作过程"><a href="#假设一个工作过程" class="headerlink" title="假设一个工作过程"></a>假设一个工作过程</h5><p>访问百度搜索主页  </p>
<p>该过程类似写信</p>
<h3 id="1-dns解析IP地址"><a href="#1-dns解析IP地址" class="headerlink" title="1.dns解析IP地址"></a>1.dns解析IP地址</h3><p>先判断本地有没有百度的dns解析,无则访问设置好的dns服务器,查询百度的ip,返回给本机,本机学习(保存到缓存中)<br><img src="/blogs/2020/02/12/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/dns%E5%8D%8F%E8%AE%AE.jpg" alt></p>
<h3 id="2-应用层数据包装"><a href="#2-应用层数据包装" class="headerlink" title="2.应用层数据包装"></a>2.应用层数据包装</h3><p>应用层判断该通信是http请求,http协议将数据包装成浏览器能识别的固定格式  </p>
<p>类似一封信的内容格式,家书有家书的格式,情书有情书的格式</p>
<h3 id="3-传输层的端口封装"><a href="#3-传输层的端口封装" class="headerlink" title="3.传输层的端口封装"></a>3.传输层的端口封装</h3><p>会在数据的上层拼接一个tcp表头,包含自己的随机端口号和百度的端口号  </p>
<p>类似信封中的收信人</p>
<h3 id="4-网络层的ip封装"><a href="#4-网络层的ip封装" class="headerlink" title="4.网络层的ip封装"></a>4.网络层的ip封装</h3><p>将自己的ip和百度的ip封装到标头,拼接到tcp标头之前  </p>
<p>ip地址类似信封中的收件人地址,具体到村</p>
<h3 id="5-数据链路层的mac地址封装"><a href="#5-数据链路层的mac地址封装" class="headerlink" title="5.数据链路层的mac地址封装"></a>5.数据链路层的mac地址封装</h3><p>此时本机只知道本机的mac地址,并不知道百度的mac地址,所以需要通过ARP协议获取网关的mac地址,将自己的mac地址和网关的mac地址封装成标头拼接到ip标头之前  </p>
<p>mac地址相当于具体到家了</p>
<h3 id="6-物理层"><a href="#6-物理层" class="headerlink" title="6.物理层"></a>6.物理层</h3><p>将拼接好的一个数据通过无线电,电缆,光缆等物理元件发送,百度服务器在以同样的过程将页面发送给本机</p>
<p>物理元件相当于公路,汽车</p>

    </div>

    
    
    

      <div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
  
</div>
      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blogs/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80/" rel="tag"># 计算机网络基础</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blogs/2020/02/08/md%E5%90%8E%E7%BC%80%E6%96%87%E4%BB%B6%E4%B9%A6%E5%86%99/" rel="prev" title="md后缀文件书写">
      <i class="fa fa-chevron-left"></i> md后缀文件书写
    </a></div>
      <div class="post-nav-item">
    <a href="/blogs/2020/02/12/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/" rel="next" title="编程语言">
      编程语言 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#引用"><span class="nav-number">1.</span> <span class="nav-text">引用</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一、什么叫计算机网络"><span class="nav-number">2.</span> <span class="nav-text">一、什么叫计算机网络</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、基础概念"><span class="nav-number">3.</span> <span class="nav-text">二、基础概念</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-协议"><span class="nav-number">3.0.1.</span> <span class="nav-text">1.协议</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-以太网"><span class="nav-number">3.0.2.</span> <span class="nav-text">2.以太网</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-数据帧"><span class="nav-number">3.0.3.</span> <span class="nav-text">3.数据帧</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-子网"><span class="nav-number">3.0.4.</span> <span class="nav-text">4.子网</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、计算机通信过程"><span class="nav-number">4.</span> <span class="nav-text">三、计算机通信过程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-osi七层协议、tcp-ip五层协议、tcp-ip四层协议"><span class="nav-number">4.0.1.</span> <span class="nav-text">1.osi七层协议、tcp&#x2F;ip五层协议、tcp&#x2F;ip四层协议</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-物理层"><span class="nav-number">4.0.2.</span> <span class="nav-text">2.物理层</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-数据链路层"><span class="nav-number">4.0.3.</span> <span class="nav-text">3.数据链路层</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3-1-以太网协议"><span class="nav-number">4.0.3.0.1.</span> <span class="nav-text">3.1 以太网协议</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-2-mac地址"><span class="nav-number">4.0.3.0.2.</span> <span class="nav-text">3.2 mac地址</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-广播"><span class="nav-number">4.0.3.0.3.</span> <span class="nav-text">3.3 广播</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-网络层"><span class="nav-number">4.0.4.</span> <span class="nav-text">4.网络层</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-IP协议"><span class="nav-number">4.0.4.0.1.</span> <span class="nav-text">1.IP协议</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-子网掩码-用于分辨两个ip是否处于同一个局域网内"><span class="nav-number">4.0.4.0.2.</span> <span class="nav-text">2.子网掩码 : 用于分辨两个ip是否处于同一个局域网内</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-IP数据包"><span class="nav-number">4.0.4.0.3.</span> <span class="nav-text">3.IP数据包</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#ARP协议"><span class="nav-number">4.0.4.0.4.</span> <span class="nav-text">ARP协议</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-传输层"><span class="nav-number">4.0.5.</span> <span class="nav-text">5.传输层</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-TCP协议"><span class="nav-number">4.0.5.0.1.</span> <span class="nav-text">1.TCP协议</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-UDP协议"><span class="nav-number">4.0.5.0.2.</span> <span class="nav-text">2.UDP协议</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-应用层"><span class="nav-number">4.0.6.</span> <span class="nav-text">6.应用层</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-网络通信模拟"><span class="nav-number">4.0.7.</span> <span class="nav-text">7.网络通信模拟</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#假设一个工作过程"><span class="nav-number">4.0.7.0.1.</span> <span class="nav-text">假设一个工作过程</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-dns解析IP地址"><span class="nav-number">4.0.8.</span> <span class="nav-text">1.dns解析IP地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-应用层数据包装"><span class="nav-number">4.0.9.</span> <span class="nav-text">2.应用层数据包装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-传输层的端口封装"><span class="nav-number">4.0.10.</span> <span class="nav-text">3.传输层的端口封装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-网络层的ip封装"><span class="nav-number">4.0.11.</span> <span class="nav-text">4.网络层的ip封装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-数据链路层的mac地址封装"><span class="nav-number">4.0.12.</span> <span class="nav-text">5.数据链路层的mac地址封装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-物理层"><span class="nav-number">4.0.13.</span> <span class="nav-text">6.物理层</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="小叶子"
      src="/blogs/images/%E5%B0%8F%E5%8F%B6%E5%AD%90.jpg">
  <p class="site-author-name" itemprop="name">小叶子</p>
  <div class="site-description" itemprop="description">也许我会走的很慢，但我不会停下来</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blogs/archives/">
        
          <span class="site-state-item-count">57</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blogs/categories/">
          
        <span class="site-state-item-count">17</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blogs/tags/">
          
        <span class="site-state-item-count">48</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/tretea" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;tretea" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/tretea" title="gitee → https:&#x2F;&#x2F;gitee.com&#x2F;tretea" rel="noopener" target="_blank"><i class="fa fa-fw fa-gitee"></i>gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:2433469529@qq.com" title="E-Mail → mailto:2433469529@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://space.bilibili.com/88409744" title="bilibili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;88409744" rel="noopener" target="_blank"><i class="fa fa-fw fa-bilibili"></i>bilibili</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">
  
  &copy; 2019 – 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-孙智超"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">孙智超</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">84k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">2:20</span>
</div>

<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_pv">
    本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blogs/lib/anime.min.js"></script>
  <script src="/blogs/lib/velocity/velocity.min.js"></script>
  <script src="/blogs/lib/velocity/velocity.ui.min.js"></script>

<script src="/blogs/js/utils.js"></script>

<script src="/blogs/js/motion.js"></script>


<script src="/blogs/js/schemes/pisces.js"></script>


<script src="/blogs/js/next-boot.js"></script>




  




  
<script src="/blogs/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: true,
      appId: 'joFkPTxLK8qvkQ7bk3l11d9w-gzGzoHsz',
      appKey: 'FoRjyOtjoXMgYfOHTlzmL1iQ',
      placeholder: "请输入您的评论",
      avatar: '小叶子',
      meta: guest,
      pageSize: '10' || 10,
      visitor: false,
      lang: '' || 'zh-cn',
      path: location.pathname,
      recordIP: false,
      serverURLs: ''
    });
  }, window.Valine);
});
</script>

<script src="/blogs/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"model":{"jsonPath":"/blogs/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":300,"height":300},"mobile":{"show":false},"log":false});</script></body>
</html>
